package com.music.controller;


import com.alibaba.fastjson.JSONObject;
import com.music.api.MusicApi;
import com.rfy.base.entity.response.BaseResponse;
import com.music.api.MusicApi;
import com.music.request.MusicSelectRequest;
import com.music.response.SongResponse;
import com.music.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.rfy.base.constant.GlobalConstants.SUCCESS;

/**
 * @author zhanghuiyong
 * @创建时间 2019年07月31日
 * @描述: 音乐模块
 **/

@RestController
@CrossOrigin
public class MusicController implements MusicApi {
    @Autowired
    private MusicService musicService;

    @Override
    @ResponseBody
    public BaseResponse queryNovel(@RequestBody MusicSelectRequest musicRequest, HttpServletResponse response) {
        BaseResponse baseResponse = new BaseResponse();
        System.out.println("开始音乐查询,查询入参" + musicRequest.toString());
        try {
            List<SongResponse> songResponses = musicService.selectMusic(musicRequest);
            baseResponse.setStatus(SUCCESS);
            baseResponse.setResult(songResponses);
        } catch (Exception e) {
            e.printStackTrace();
            baseResponse.setMessage(e.getMessage());
        }
        System.out.println("结束音乐查询,查询返参" + JSONObject.toJSONString(baseResponse));
        return baseResponse;
    }
}
